package Java常用工具API.String类;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * 字符串，字节数组，字符数组之间的相互转换
 */
public class StringToBytesToCharsTest {
    public static void main(String[] args) {
        ArrayList<Object> objects = new ArrayList<>();
        objects.add("1");
        objects.add("2");
        objects.add("3");
        Object o = objects.get(0);
        Object o1 = objects.get(1);
        objects.remove("1");
        objects.remove(o1);
        objects.add("4");
        System.out.println(objects);
        System.out.println("--------------------");

        //测试字符串，字节数组，字符数组等之间的相关转化
        String str = "i like like like java do you like a java";//长度40个字符
        //快速将字符串转化为字符数组
        char[] chars = str.toCharArray();
        System.out.println(Arrays.toString(chars));
        System.out.println("-------------------------");
        //快速将字符串转化为字节数组
        byte[] bytes = str.getBytes();
        System.out.println(Arrays.toString(bytes));
        System.out.println("-------------------------");
        //快速将字节数组转化为字符串
        String str2 = new String(bytes);
        System.out.println(str2);
        System.out.println("-------------------------");
        //快速将字符数组转化为字符串:两种方式
        String str3 = new String(chars);
        System.out.println(str3);
        String s = String.valueOf(chars);
        System.out.println(s);
        //字节数组转化为字符数组，可以先将字节数组转化为字符串，再将字符串转化为字符数组
    }
}
